import Vue from "vue";
import Vuex from "vuex";

Vue.use(Vuex);

const store = new Vuex.Store({
  state: {
    userInfo: {},
  },
  mutations: {
    login(state, provider) {
      state.userInfo = provider;
      uni.setStorage({
        //缓存用户登陆状态
        key: "userInfo",
        data: provider,
      });

      uni.setStorage({
        //缓存用户登陆状态
        key: "token",
        data: provider["tokenValue"],
      });
    },
    logout(state) {
      state.userInfo = {};
      uni.removeStorage({
        key: "userInfo",
      });
      uni.removeStorage({
        key: "token",
      });
    },
  },
  actions: {},
});

export default store;
